package gee

import "fmt"

type Router struct {
	handlers map[string]HandleFunc
}

func NewRouter() *Router {
	return &Router{
		handlers: make(map[string]HandleFunc),
	}
}

func (router *Router) addRouter(method, pattern string, handler HandleFunc) {
	key := method + "-" + pattern
	router.handlers[key] = handler
}

func (router *Router) handle(c *Context) {
	key := c.Method + "-" + c.Path
	if handler, ok := router.handlers[key]; ok {
		handler(c)
	} else {
		fmt.Fprintf(c.Writer, "404 NOT FOUND %s\n", c.Path)
	}
}
